package com.bole.service.impl;

import com.bole.dao.CarDao;
import com.bole.dao.OrderDao;
import com.bole.pojo.TbCarDo;
import com.bole.pojo.TbOrderDo;
import com.bole.service.OrderService;
import com.bole.util.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class OrderServiceImpl implements OrderService {


    @Autowired
    private OrderDao orderDao;

    @Autowired
    private CarDao carDao;

    @Autowired
    private IdWorker idWorker;


    @Override
    public TbOrderDo save(Long carId,TbOrderDo orderDo) {
        TbCarDo tbCarDo = carDao.findById(carId).get();
        orderDo.setId(idWorker.nextId());
        //获取卖家Id，手机号，价格
        orderDo.setCarId(tbCarDo.getId());
        orderDo.setSellUserId(tbCarDo.getSellUserId());
        orderDo.setSellTelephone(tbCarDo.getSellPhone());
        orderDo.setPrice(tbCarDo.getPrice());
        //付款状态为0
        //创建时间
        orderDo.setCreateTime(new Date());
        orderDo.setStatus("0");
        TbOrderDo save = orderDao.save(orderDo);
        return save;
    }

    @Override
    public TbOrderDo updateOrder(TbOrderDo order) {
        return orderDao.save(order);
    }

    @Override
    public TbOrderDo findById(Long id) {
        return orderDao.findById(id).get();
    }
}
